home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcombo.exe / TCMBOWIN.CPP < prev    next >
C/C++ Source or Header  |  1992-11-18  |  3KB  |  107 lines

  1. /*************************************************************************/
  2. /*                                                                       */
  3. /* TCMBOWIN.CPP                                                          */
  4. /*                                                                       */
  5. /* Copyright (c) 1992, Vincent J. Dentice                                */
  6. /* All rights reserved                                                   */
  7. /*                                                                       */
  8. /* The TComboBox class is an extension to Borland International's Turbo  */
  9. /* Vision Applications Framework for DOS.  It provides a class that      */
  10. /* acts like a Combo Box in other graphical environments like Microsoft  */
  11. /* Windows and IBM OS/2.                                                 */
  12. /*                                                                       */
  13. /* It is designed to be with a TDialog class and a TCollection Class.    */
  14. /*                                                                       */
  15. /*                                                                       */
  16. /*   Date    Prg  Ver  Description                                       */
  17. /* --------  ---  ---  ------------------------------------------------- */
  18. /* 09/30/92  VJD  0.1  Initial module definition.                        */
  19. /* 11/16/92  VJD  0.2  Added streamability to the TComboBox classes.     */
  20. /*                                                                       */
  21. /*************************************************************************/
  22.  
  23.  
  24. #define Uses_TComboWindow
  25. #define Uses_TScrollBar
  26. #define Uses_TStreamableClass
  27. #include "tcombobx.h"
  28.  
  29. #define cpComboWindow "\x13\x13\x15\x04\x05\x1A\x1C"
  30.  
  31.  
  32. TComboWindow::TComboWindow(const TRect& bounds, TCollection *aList) :
  33.             TWindow(bounds, 0, wnNoNumber),
  34.             TWindowInit(&TComboWindow::initFrame)
  35. {
  36.    TRect r;
  37.    TScrollBar  *sb;
  38.    TComboViewer *cv;
  39.  
  40.    setState(sfShadow, False);
  41.    flags = 0;
  42.  
  43.    r = getExtent();
  44.    r.a.x = r.b.x - 1;
  45.    sb = new TScrollBar(r);
  46.    insert(sb);
  47.  
  48.    r = getExtent();
  49.    r.b.x--;
  50.    viewer = new TComboViewer(r, aList, sb);
  51.    insert(viewer);
  52. }
  53.  
  54.  
  55. TPalette& TComboWindow::getPalette() const
  56. {
  57.    static TPalette palette (cpComboWindow, sizeof(cpComboWindow)-1);
  58.    return palette;
  59. }
  60.  
  61.  
  62. void TComboWindow::getSelection(char *dest)
  63. {
  64.    viewer->getText(dest, viewer->focused, 255);
  65. }
  66.  
  67.  
  68. void TComboWindow::handleEvent(TEvent& event)
  69. {
  70.    if ((event.what == evMouseDown) && !containsMouse(event)) {
  71.       endModal(cmCancel);
  72.       clearEvent(event);
  73.    }
  74.    TWindow::handleEvent(event);
  75. }
  76.  
  77.  
  78. void TComboWindow::setSelection(char *data)
  79. {
  80.    viewer->focusItem(viewer->list->indexOf(data));
  81. }
  82.  
  83.  
  84. void * TComboWindow::read( ipstream& is )
  85. {
  86.    TWindow::read(is);
  87.    is >> viewer;
  88.    return this;
  89. }
  90.  
  91. void TComboWindow::write( opstream& os )
  92. {
  93.    TWindow::write(os);
  94.    os << viewer;
  95. }
  96.  
  97.  
  98. TStreamable *TComboWindow::build()
  99. {
  100.    return new TComboWindow(streamableInit);
  101. }
  102.  
  103.  
  104. TComboWindow::TComboWindow(StreamableInit) : TWindow(streamableInit),
  105.                          TWindowInit(0)
  106. {}
  107.